package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teach=new Teacher[5];
    static {
        Teacher teacher=new Teacher("heima001","张三","23","1999-09-09");
        Teacher teacher1=new Teacher("heima002","李四","24","2000-09-09");
        teach[0]=teacher;
        teach[1]=teacher1;

    }
    //返回一个数组方法
    public static Teacher[] inquire() {
        return teach;
    }

    public static Teacher[] watcher() {
        return teach;
    }

    public boolean addTeacher(Teacher teacher) {
        
        int index=-1;
        for (int i = 0; i < teach.length; i++) {
            if (teach[i]==null){
                index=i;
                break;
            }
        }
        if (index==-1){
            return false;
        }else{
            teach[index]=teacher;
            return true;
        }
    }
    //在数组中找到id所在的索引并删除
    public boolean delete(String id) {
        for (int i = 0; i < teach.length; i++) {
            if (teach[i]!=null&&id.equals(teach[i].getID())){
                teach[i]=null;
                return true;
            }
        }
        return false;
    }
    //根据工号来确定老师的索引，从而更改信息
    public boolean change(String id, String name, String age, String birth) {
        for (int i = 0; i < teach.length; i++) {
            if (teach[i]!=null&&id.equals(teach[i].getID())){
                teach[i].setName(name);
                teach[i].setAge(age);
                teach[i].setBirthday(birth);
                return true;
            }
        }
        return false;
    }
}
